﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Google.GData.Photos;
using Google.GData.Client;
using Google.GData.Extensions;
using Google.GData.Extensions.Location;

namespace WapCrawler.Testing
{
    public partial class frmPicasaAPI : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void btnPostPhoto_Click(object sender, EventArgs e)
        {
            //if (FileUploadControl.HasFile)
            //{
            //    try
            //    {
            //        if (FileUploadControl.PostedFile.ContentType == "image/jpeg")
            //        {
                        
            //            PicasaService service = new PicasaService("exampleCo-exampleApp-1");
            //            service.setUserCredentials(txtUsername.Text, txtPassword.Text);

            //            //Uri postUri = new Uri(PicasaQuery.CreatePicasaUri(txtUsername.Text, albumid));
            //            Uri postUri = new Uri("https://picasaweb.google.com/data/feed/api/user/default/albumid/default");
            //            System.IO.FileInfo fileInfo = new System.IO.FileInfo(FileUploadControl.FileName);
            //            System.IO.FileStream fileStream = fileInfo.OpenRead();

            //            PicasaEntry entry = (PicasaEntry)service.Insert(postUri, fileStream, "image/jpeg", FileUploadControl.FileName);

            //            fileStream.Close();
            //        }
            //    }
            //    catch (Exception ex)
            //    {
            //    }
            //}

            PicasaService service = new PicasaService("exampleCo-exampleApp-1");
            service.setUserCredentials(txtUsername.Text, txtPassword.Text);

            //Uri postUri = new Uri(PicasaQuery.CreatePicasaUri(txtUsername.Text, albumid));
            Uri postUri = new Uri("https://picasaweb.google.com/data/feed/api/user/default/albumid/default");
            System.IO.FileInfo fileInfo = new System.IO.FileInfo("F:\\2cR7W.jpg");
            System.IO.FileStream fileStream = fileInfo.OpenRead();

            PicasaEntry entry = (PicasaEntry)service.Insert(postUri, fileStream, "image/jpeg", FileUploadControl.FileName);

            string url = entry.Media.Content.Attributes["url"] as string;
            fileStream.Close();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (FileUploadControl.HasFile)
            {
                try
                {
                    if (FileUploadControl.PostedFile.ContentType == "image/jpeg")
                    {
                        //if (FileUploadControl.PostedFile.ContentLength < 102400)
                        //{
                            string filename = Path.GetFileName(FileUploadControl.FileName);

                            //FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
                            //StatusLabel.Text = "Upload status: File uploaded!";
                        //}
                        //else
                        //    StatusLabel.Text = "Upload status: The file has to be less than 100 kb!";
                    }
                    //else
                    //    StatusLabel.Text = "Upload status: Only JPEG files are accepted!";
                }
                catch (Exception ex)
                {
                    //StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                }
            }
        }
    }
}